"""
@file: shop-cart.py
@author: yangsiting
@data: 2021/04/27
@desc:
"""
from .base import db
from .user import UserProfile
from .goods import Goods_info

# 购物车信息

class Shop_cart_Info(db.Model):
    __tablename__ = "shop_cart"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_profile_id = db.Column(db.ForeignKey('user_profile.user_profile_id'))
    goods_id = db.Column(db.Integer,db.ForeignKey('goods_info.goods_id'))
    goods_num = db.Column(db.Integer)
    # goods_price = db.Column(db.String(20))
    # total = db.Column(db.String(20))

    # 对模型常用的操作，都可以封装成一个方法,类方法
    @classmethod
    def create_info(cls,user_profile_id,goods_id,goods_num):
        info = cls()
        info.user_profile_id = user_profile_id
        info.goods_id = goods_id
        info.goods_num = goods_num
        db.session.add(info)
        db.session.commit()